package com.xbenben.project.demo.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.HeaderParam;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author yu.zhijia
 * Date:2022/12/27 22:17
 **/
@RestController
@RequestMapping("/demo")
@Slf4j
public class DemoCollectron {

    @Autowired
    RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;


    private void createBigObject() {
        // 创建一个大对象
        threadPoolTaskExecutor.submit(() -> {
            // 创建大量的字符串对象
            List<String> bigObject = new ArrayList<>();

            for (int i = 0; i < 1000; i++) {
                String str = "String" + i;
                bigObject.add(str);
                log.info("bigObject: {}", bigObject);
            }
        });
    }

    private void createFakeData() {
        threadPoolTaskExecutor.submit(() -> {
            // 制造虚假数据
            List<String> fakeData = new ArrayList<>();
            for (int i = 0; i < 1000; i++) {
                String data = "Data" + i;
                fakeData.add(data);
                log.info("fakeData: {}", fakeData);
            }
        });

    }

    @PostMapping("/test")
    public String testDemo(@HeaderParam("timestamp") Long timestamp, @HeaderParam("sign") String sign, @RequestBody String payload) {
        String s = JSON.toJSONString(payload);
        log.info("-------213--payload: {}", s);

        String jsonStr = "{\n" +
                "    \"msgtype\": \"markdown\",\n" +
                "    \"markdown\": {\n" +
                "        \"title\": \"查询哪个问题\",\n" +
                "        \"text\":\"请输入你想问的问题：  > 【可@小助手进行关键字查询：1、运营百科，2、运营百科热点问题，3、查询知识列表，4、行政问答】\"}\n" +
                "        }";
        System.out.println(jsonStr);
        return jsonStr;
    }

}
